package com.Servlet;

import java.io.IOException;
import java.util.List;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Business.GetUserRemote;
import com.Entity.CompanyUser;

/**
 * Servlet implementation class GetUser
 */
@WebServlet("/GetUser")
public class GetUser extends HttpServlet {

    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public GetUser() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     * response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        Context ctx;
        String result = "";
        List<CompanyUser> list = null;
        CompanyUser aUser = null;
        try {
            ctx = new Connection().ctx;
            GetUserRemote remote = (GetUserRemote) ctx.lookup("java:global/ManTechHelpdesk-Ejb/GetUser");
            if (remote.findNewUser() != null) {
                result += "Co' list user ";
                list = remote.findNewUser();
                aUser = remote.findNewUser().get(0);
            }
            result += aUser.getDateOfBirth();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        response.setContentType("text/html");
        response.getWriter().println(result);
        response.getWriter().println(list);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
     * response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}
